package com.ruoyi.consumer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.consumer.domain.CUnitPrice;
import com.ruoyi.consumer.service.ICUnitPriceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单价Controller
 * 
 * @author ruoyi
 * @date 2023-10-29
 */
@RestController
@RequestMapping("/consumer/unitPrice")
public class CUnitPriceController extends BaseController
{
    @Autowired
    private ICUnitPriceService cUnitPriceService;

    /**
     * 查询单价列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:list')")
    @GetMapping("/list")
    public TableDataInfo list(CUnitPrice cUnitPrice)
    {
        startPage();
        List<CUnitPrice> list = cUnitPriceService.selectCUnitPriceList(cUnitPrice);
        return getDataTable(list);
    }

    /**
     * 导出单价列表
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:export')")
    @Log(title = "单价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CUnitPrice cUnitPrice)
    {
        List<CUnitPrice> list = cUnitPriceService.selectCUnitPriceList(cUnitPrice);
        ExcelUtil<CUnitPrice> util = new ExcelUtil<CUnitPrice>(CUnitPrice.class);
        util.exportExcel(response, list, "单价数据");
    }

    /**
     * 获取单价详细信息
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") Integer unitId)
    {
        return success(cUnitPriceService.selectCUnitPriceByUnitId(unitId));
    }

    /**
     * 新增单价
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:add')")
    @Log(title = "单价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CUnitPrice cUnitPrice)
    {
        return toAjax(cUnitPriceService.insertCUnitPrice(cUnitPrice));
    }

    /**
     * 修改单价
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:edit')")
    @Log(title = "单价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CUnitPrice cUnitPrice)
    {
        return toAjax(cUnitPriceService.updateCUnitPrice(cUnitPrice));
    }

    /**
     * 删除单价
     */
    @PreAuthorize("@ss.hasPermi('consumer:unitPrice:remove')")
    @Log(title = "单价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable Integer[] unitIds)
    {
        return toAjax(cUnitPriceService.deleteCUnitPriceByUnitIds(unitIds));
    }
}
